package com.hotelManagerSystem.mapper;

import com.hotelManagerSystem.model.Role;
import com.hotelManagerSystem.model.StaffRole;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  职工——角色 Mapper 接口
 * </p>
 *
 * @author longyajr
 * @since 2021-12-22
 */
public interface StaffRoleMapper extends BaseMapper<StaffRole> {

    @Delete("DELETE FROM staff_role WHERE staff_id = #{staffId}")
    Boolean deleteStaffRoleByStaffId(int staffId);

    @Delete("DELETE FROM staff_role WHERE role_id = #{roleId}")
    Boolean deleteStaffRoleByRoleId(int roleId);

    /**
     * @author treasy
     * @description 根据员工Id查询所有角色信息
     * @param staffId
     * @return
     */
    @Select("SELECT\n" +
            "role.role_id,\n" +
            "role.role_name,\n" +
            "role.role_code\n" +
            "FROM\n" +
            "staff\n" +
            "INNER JOIN staff_role ON staff.staff_id = staff_role.staff_id\n" +
            "INNER JOIN role ON staff_role.role_id = role.role_id\n" +
            "WHERE\n" +
            "staff.staff_id = #{staffId}")
    List<Role> queryAllRoleByStaffId(int staffId);
}
